package com.konsung.ksdc.manager.machine;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.konsung.ksdc.R;
import com.konsung.ksdc.bean.netbean.MachineNetBean;
import com.konsung.ksdc.config.MyApplication;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * 一体机适配器
 * Created by Administrator on 2016/3/14 0014.
 */
public class MyMachineAdapter extends BaseAdapter {
    private List<MachineNetBean> machineNetBeanList = new ArrayList<>();

    /**
     * 构造方法
     */
    public MyMachineAdapter() {
    }

    /**
     * 构造方法
     * @param machineList 一体机数据集合
     */
    public MyMachineAdapter(List<MachineNetBean> machineList) {
        machineNetBeanList = machineList;
    }

    @Override
    public int getCount() {
        return machineNetBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return machineNetBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        MachineNetBean bean = machineNetBeanList.get(position);

        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(MyApplication.getContext())
                    .inflate(R.layout
                    .item_listview_mymachine, null);
            ButterKnife.bind(holder, convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.tvName.setText(bean.getMacName());
        holder.tvSerialNum.setText(bean.getSerialNum());

        return convertView;
    }

    /**
     * 适配器类
     */
    static class ViewHolder {
        @Bind(R.id.tv_name)
        TextView tvName;
        @Bind(R.id.tv_serial_number)
        TextView tvSerialNum;
    }

    /**
     * 设置更新数据
     * @param machineList 一体机数据集合
     */
    public void setData(List<MachineNetBean> machineList) {
        machineNetBeanList = machineList;
        notifyDataSetChanged();
    }
}
